﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="content-type" content="txt/html charset=utf-8" />
    <title>批次调度</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style type="text/css">
        .combobox-item
        {
            font-size: 14px;
            padding: 3px 4px;
            line-height: 14px;
        }
    </style>
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="基本信息" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin-left: -10px">
                <div style="float: left; margin-left: 10px; margin-bottom: 5px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        当前批次：</div>
                    <input id="txtContainerNameShow" class="easyui-textbox" name="factoryID" type="text"
                        data-options="readonly:true" style="width: 200px; height: 22px" />
                </div>
                <div style="float: left; margin-left: 10px; margin-bottom: 5px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        产品图号：</div>
                    <input id="txtProductName" class="easyui-textbox" name="factoryID" type="text" data-options="readonly:true"
                        style="width: 150px; height: 22px" />
                </div>
                <div style="float: left; margin-left: 10px; margin-bottom: 5px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        产品名称：</div>
                    <input id="txtProductDesc" class="easyui-textbox" name="factoryID" type="text" data-options="readonly:true"
                        style="width: 150px; height: 22px" />
                </div>
                <div style="float: left; margin-left: 10px; margin-bottom: 5px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        批次数量：</div>
                    <input id="txtContainerQty" class="easyui-textbox" name="factoryID" type="text" data-options="readonly:true"
                        style="width: 80px; height: 22px" />
                </div>
                <div style="clear: both">
                </div>
                <div style="float: left; margin-left: 10px; margin-bottom: 5px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        当前工艺路线级版本：</div>
                    <input id="txtWorkflow" class="easyui-textbox" name="factoryID" type="text" data-options="readonly:true"
                        style="width: 360px; height: 22px" />
                </div>
                <div style="float: left; margin-left: 10px; margin-bottom: 5px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        当前工序：</div>
                    <input id="txtStepName" class="easyui-textbox" name="factoryID" type="text" data-options="readonly:true"
                        style="width: 240px; height: 22px" />
                </div>
            </div>
        </div>
    </div>
    <div id="dvRelease" class="panelSection">
        <div class="easyui-panel " title="释放信息" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="float: left; margin-left: 0px">
                <div class="divLabel" style="margin-bottom: 5px;">
                    释放原因：</div>
                <input id="ddlReleaseReason" class="easyui-combobox" name="ddlReleaseReason" type="text"
                    data-options="panelHeight:200,valueField:'REASONID',
                textField:'REASONNAME',url:page.ajaxUrl+'?action=getReleaseReason'" style="width: 180px;
                    height: 22px" />
            </div>
            <div style="float: left; margin-left: 10px; margin-top: 20px">
                或
            </div>
            <div style="float: left; margin-left: 10px; margin-top: 0px">
                <div class="divLabel" style="margin-bottom: 5px;">
                    释放原因：</div>
                <input id="txtReleaseReason" class="easyui-textbox" name="ReleaseReason" type="text"
                    data-options="multiline:true" style="width: 270px; height: 40px" />
            </div>
            <div style="float: left; margin-left: 10px; margin-top: 0px">
                <div class="divLabel" style="margin-bottom: 5px;">
                    是否调度：</div>
                <select id="ddlIsMoveNon" class="easyui-combobox" name="IsMoveNon" data-options="panelHeight:50"
                    style="width: 60px; height: 22px">
                    <option value="是">是</option>
                    <option value="否">否</option>
                </select>
            </div>
        </div>
    </div>
    <div id="dvMoveNon" class="panelSection">
        <div class="easyui-panel " title="产品工艺信息" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="height: 130px">
                <div style="float: left; margin-top: 16px">
                    <input class="" id="ckCurProduct" name="curProduct" value="当前产品" checked="true" type="checkbox">
                    <label for="ckCurProduct">
                        当前产品</label>
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        产品：</div>
                    <input id="ddlProduct" class="easyui-combobox" name="ddlProduct" type="text" data-options="disabled:true"
                        style="width: 180px; height: 22px" />
                </div>
                <div style="float: left; margin-top: 16px; display: none;">
                    <input class="" id="ckCurUseWorkFlow" name="curUseWorkFlow" value="有效版" type="checkbox">
                    <label for="ckUseWorkFlow">
                        有效版</label>
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        工艺：</div>
                    <input id="ddlWorkflow" class="easyui-combobox" name="ddlWorkflow" type="text" data-options=""
                        style="width: 250px; height: 22px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        工序：</div>
                    <input id="ddlWorkflowStep" class="easyui-combobox" name="ddlWorkflowStep" type="text"
                        data-options="panelHeight:200" style="width: 250px; height: 22px" />
                </div>
                <div style="clear: both">
                </div>
                <div style="float: left; margin-left: 0px; margin-top: 20px">
                    <div class="divLabel" style="margin-bottom: 5px;">
                        调度原因：</div>
                    <input id="txtMoveReason" class="easyui-textbox" name="factoryID" type="text" data-options="multiline:true"
                        style="width: 270px; height: 40px" />
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="按钮区域" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div id="dv-btnConRelease" style="float: left; margin-left: 0px; display: none">
                <a href="#" id="btnConRelease" class="easyui-linkbutton" data-options="" style="">批次释放</a>
            </div>
            <div id="dv-btnChangeWF" style="float: left; margin-left: 0px">
                <a href="#" id="btnChangeWF" class="easyui-linkbutton" data-options="" style="">切换工艺</a>
            </div>
            <div id="dv-btnChangeP" style="float: left; margin-left: 20px">
                <a href="#" id="btnChangeP" class="easyui-linkbutton" data-options="" style="">切换产品</a>
            </div>
            <div style="float: left; margin-left: 20px">
                <a href="#" id="btnClose" class="easyui-linkbutton" data-options="" style="">关闭</a>
            </div>
        </div>
    </div>
    <div id="dg" style="display: none">
        <div style="margin-left: 10px">
            <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                调度前所在序：</div>
            <input id="ddlPreStep" class="easyui-combobox" name="ddlWorkflowStep" type="text"
                data-options="panelHeight:200" style="width: 250px; height: 22px" />
        </div>
        <div style="margin-left: 10px; margin-top: 10px">
            <div class="divLabel" style="width: 100px; text-align: right; display: inline-block">
                调度后开始序：</div>
            <input id="ddlApsToStep" class="easyui-combobox" name="ddlWorkflowStep" type="text"
                data-options="panelHeight:200" style="width: 250px; height: 22px" />
        </div>
        <div style="margin-left: 10px; margin-top: 10px">
            <div class="divLabel" style="width: 100px; text-align: right; display: inline-block">
                调度后开始时间：</div>
            <input id="txtApsStartDate" type="text" class="easyui-datetimebox" style="height: 20px;
                width: 250px" />
        </div>
        <div style="color: red; font-size: 14px; line-height: 18px; margin-left: 10px; margin-top: 10px">
            按照调度后开始序，取指定时间开始进行正排，排产结果需要到【排产下发回收】功能进行下达
        </div>
        <div style="margin-top: 20px; text-align: right; padding-right: 10px">
            <a href="#" id="btnApsChange" class="easyui-linkbutton" data-options="" style="width: 80px">
                确定</a> <a href="#" id="btnApsCancel" class="easyui-linkbutton" data-options="" style="margin-left: 10px;
                    width: 80px">取消</a>
        </div>
    </div>
    <!--<div id="statusMessage" style="font-size: 14px; height: 20px; margin-top: 10px"></div>-->
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    var page = {
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ContainerManagePlatHandler.ashx",
        param: [{ "MfgOrderName": "yp20211013001", "ProductBatch": "YPProduct001/2021", "ContainerType": "3", "ProductName": "YPProduct001", "TogetherFlag": "YPProduct001/2021", "ProductID": "00062c8000004f67", "ProductDesc": "叶片测试产品", "ProductRevision": "1", "WorkFlowStepID": "00074e8000005093", "WorkFlowName": "WF-YPProduct001:1", "WorkFlowID": "4800268000004a09", "WorkFlowRevision": "1", "ContainerTypeName": "批量带子序号", "WorkFlowStepName": "YPProduct001-5-粗加工", "Qty": "8", "Process_No": null, "ProductBatchHidden": "YPProduct001/2021", "ckSelect": "True", "ContainerName": "YPProduct001/2021", "CheckTechnique": "叶片管理员", "techniqueemployeeid": "已校对", "ContainerStatus": "待派工", "IsDispatch": "否", "IsWorkReport": "否", "IsChecked": "否", "IsCommissioning": "否", "IsShip": "否", "IsSplit": "否", "IsHold": "否", "IsHaveSurpass": null, "ContainerID": "000410800000561b", "StartEmployeeID": "00047480000071ea", "WorkReportNum": "0", "NonconNum": "0", "isinstore": "0", "CheQty": "0", "DisQty": "0", "type": ""}],
        pageType: "", //2:装试
        pageStatus: 'loading',
        isIncludePause: '0', //是否包含暂停/释放逻辑
        parentID: "",
        WorkFlowIsUse:"",
        //初始化页面
        init: function () {
            page.bind();
            page.initData();

        },
        //页面事件绑定
        bind: function () {
            //产品
            $("#ddlProduct").combobox({
                panelHeight: '200',
                valueField: 'ProductID',
                textField: 'ProductInfo',
                onChange: function (newValue, oldValue) {
                    $("#ddlWorkflow").combobox('clear');
                    page.loadWorkflow();
                    //alert(1);
                }
            });
            //工艺
            $("#ddlWorkflow").combobox({
                panelHeight: '200',
                valueField: 'WORKFLOWID',
                textField: 'WORKFLOWNAME',
                onChange: function (newValue, oldValue) {
                    $("#ddlWorkflowStep").combobox('clear');
                    page.loadWorkflowStep();
                }
            });
            //工序
            $("#ddlWorkflowStep").combobox({
                panelHeight: '200',
                valueField: 'WORKFLOWSTEPID',
                textField: 'WORKFLOWSTEPNAME',
                onChange: function (newValue, oldValue) {
                    $("#ddlApsToStep").combobox('select', newValue);
                }
            });
            //排产所在序
            $("#ddlApsToStep").combobox({
                panelHeight: '200',
                valueField: 'WORKFLOWSTEPID',
                textField: 'WORKFLOWSTEPNAME'
            });
            //调度前工序
            $("#ddlPreStep").combobox({
                panelHeight: '200',
                valueField: 'WORKFLOWSTEPID',
                textField: 'WORKFLOWSTEPNAME'
            });
            //切换工艺
            $('#btnChangeWF').on("click", function () {
                page.moveNonStd();

            });
            //排产取消
            $('#btnApsCancel').on("click", function () {
                parent.$("#" + page.parentID).dialog('options').returnData = true;
                parent.$("#" + page.parentID).dialog('close');
            });
            //重新排产
            $('#btnApsChange').on("click", function () {
                page.moveNonApsChange();
            });

            //切换产品
            $('#btnChangeP').on("click", function () {
                page.changeProduct();
            });

            //批次释放
            $('#btnConRelease').on("click", function () {
                page.releaseConAndMoveNon();
            });

            //关闭
            $('#btnClose').on("click", function () {
                parent.$("#" + page.parentID).dialog('close');
            });

            //当前产品选中
            $("#ckCurProduct").on("change", function () {
                var val = $("#ckCurProduct").is(":checked");
                if (val) {
                    $("#ddlProduct").combobox('disable');
                } else {
                    $("#ddlProduct").combobox('enable');
                }
            })

            //是否调度
            $("#ddlIsMoveNon").combobox({
                onSelect: function (record) {
                    //alert(record.value);
                    if (record.value == "是") {
                        $("#dvMoveNon").css("display", "block");
                    } else {
                        $("#dvMoveNon").css("display", "none");
                    }
                }
            });


            //是否有效版
            $("#ckCurUseWorkFlow").on("change", function () {
                var val = $("#ckCurUseWorkFlow").is(":checked");         
                if (val) {
                page.WorkFlowIsUse = "0";            
                } else {
                page.WorkFlowIsUse = "";
                }
                //alert(page.WorkFlowIsUse );
                page.loadWorkflow();
            })


        },
        initData: function () {
            page.parentID = getParam("parentDiv");
            //page.param = JSON.parse(decodeURIComponent(getParam("param")));
            page.param = JSON.parse(parent.$("#" + page.parentID).dialog('options').popupData);
            parent.$("#" + page.parentID).dialog('options').popupData = '';
            page.pageType = page.param[0].type;
            page.isIncludePause = getParam("pausePage");
            //alert(page.isIncludePause);
            $("#txtContainerNameShow").textbox('setValue', page.param[0].ContainerName);
            $("#txtProductName").textbox('setValue', page.param[0].ProductName);
            $("#txtProductDesc").textbox('setValue', page.param[0].ProductDesc);
            $("#txtContainerQty").textbox('setValue', page.param[0].Qty);
            $("#txtWorkflow").textbox('setValue', page.param[0].WorkFlowName);
            $("#txtStepName").textbox('setValue', page.param[0].WorkFlowStepName);

            if (page.pageType != "2") { //不是装试
                if (page.param.find(function (item) {
                    return item.IsShip == "是";
                }) != null) {
                    displayMessage("选择的批次存在转工未转回", false);
                    $("#btnChangeWF").linkbutton('disable');
                }

                if (page.param.find(function (item) {
                    return item.iscommissioning == "是";
                }) != null) {
                    displayMessage("选择的批次存在外委未转回", false);
                    $("#btnChangeWF").linkbutton('disable');
                }

                if (page.param.find(function (item) {
                    return item.IsSplit == "是";
                }) != null) {
                    displayMessage("选择的批次存在未分批完的", false);
                    $("#btnChangeWF").linkbutton('disable');
                }

                if (page.param.find(function (item) {
                    return item.IsWorkReport == "是";
                }) != null) {
                    displayMessage("选择的批次存在报工不能调度工艺", false);
                    $("#btnChangeWF").linkbutton('disable');
                }
            }

            if (page.isIncludePause != "1") {
                $("#dvRelease").css("display", "none");
            } else {
                $("#dv-btnConRelease").css("display", "block");
                $("#dv-btnChangeWF").css("display", "none");
                $("#dv-btnChangeP").css("display", "none");
            }
            page.loadProduct();



        },
        loadWorkflowStep: function () {
            //请求后台，初始化数据
            var postData = {
                action: "moveNon_InitStepData",
                workflowId: $("#ddlWorkflow").combobox('getValue'),
                containerId: page.param[0].ContainerID,
                containerName: page.param[0].ContainerName
            };
            if (isNullOrWhiteSpaceStr(postData.workflowId)) {
                return;
            }
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        //初始化工序
                        $("#ddlWorkflowStep").combobox('loadData', result.ReturnData.WorkflowStepDt);
                        if (result.ReturnData.WorkflowStepDt.find(function (item) {
                            return item.WORKFLOWSTEPID == page.param[0].WorkFlowStepID;
                        }) != null) {
                            $("#ddlWorkflowStep").combobox('select', page.param[0].WorkFlowStepID);
                        } else {
                            $("#ddlWorkflowStep").combobox('select', result.ReturnData.WorkflowStepDt[0].WORKFLOWSTEPID);
                        }
                        //排产目标工序
                        $("#ddlApsToStep").combobox('loadData', result.ReturnData.WorkflowStepDt);
                        if (page.pageStatus == "loading") {//首次加载 
                            //第一次加载完成后，赋值给ddlPreStep，调度前的工序信息  
                            $("#ddlPreStep").combobox('loadData', result.ReturnData.WorkflowStepDt);
                            $("#ddlPreStep").combobox('select', $("#ddlWorkflowStep").combobox('getValue'));
                            page.pageStatus = "loaded";
                        }
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        loadWorkflow: function () {
            //请求后台，初始化数据
            var postData = {
                action: "moveNon_InitWorkflowData",
                productName: $("#txtProductName").textbox('getValue'),
                productRev: $("#ddlProduct").combobox('getText').split(':')[1],
                curWorkflowId: page.param[0].WorkFlowID,
                WorkFlowIsUse: page.WorkFlowIsUse,
            };
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        //初始化工艺
                        $("#ddlWorkflow").combobox('loadData', result.ReturnData.WorkflowDt);    
                        //判断有效工艺是否存在当前工艺             
                        var isexists=false;
                        $.each(result.ReturnData.WorkflowDt,function(key,value){
                        if(value.WORKFLOWID==page.param[0].WorkFlowID)
                        {
                          isexists=true;
                          return false;
                        }
                        });
                         if(isexists)
                         {
                         $("#ddlWorkflow").combobox('select', page.param[0].WorkFlowID);
                         }
                         else{
                         $("#ddlWorkflow").combobox('select',(result.ReturnData.WorkflowDt.length>0?result.ReturnData.WorkflowDt[0].WORKFLOWID:""));
                         }
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        loadProduct: function () {

            //请求后台，初始化数据
            var postData = {
                action: "moveNon_InitProductData",
                productName: $("#txtProductName").textbox('getValue')
            };
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        //初始化产品
                        $("#ddlProduct").combobox('loadData', result.ReturnData.ProductDt);
                        $("#ddlProduct").combobox('select', page.param[0].ProductID);

                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });

        },
        //打开重新排产弹出框
        openChangeAps: function () {
            $('#txtApsStartDate').datetimebox('setValue', dayjs().format("YYYY-MM-DD HH:mm"));
            if ($("#ddlPreStep").combobox("getText") == $("#ddlApsToStep").combobox("getText")) {
                $("#ddlPreStep").combobox("disable");
                $("#ddlApsToStep").combobox("disable");
            } else {
                $("#ddlPreStep").combobox("enable");
                $("#ddlApsToStep").combobox("enable");
            }
            $('#dg').dialog({
                title: '批次调度后计划重排',
                top: 10,
                width: 400,
                height: 250,
                closed: false,
                cache: false,
                modal: true,
                returnData: null,
                popupData: '', //弹出页面的传参
                onClose: function () {
                    var returnData = $("#dg").dialog('options').returnData; //返回数据
                    if (returnData != null) {

                    }

                    parent.$("#" + page.parentID).dialog('options').returnData = true;
                    parent.$("#" + page.parentID).dialog('close');
                }
            });
        },
        //批次释放和非标移动
        releaseConAndMoveNon: function () {

            //请求后台，初始化数据
            var postData = {
                action: "releaseAndMoveNon",
                pageType: page.pageType,
                moveNon: $("#ddlIsMoveNon").combobox('getValue'),
                curWorkflowId: page.param[0].WorkFlowID,
                reason: $("#txtMoveReason").textbox('getValue'),
                operReason: isNullOrWhiteSpaceStr($("#txtReleaseReason").textbox('getValue')) ? $("#ddlReleaseReason").combobox('getValue') : $("#txtReleaseReason").textbox('getValue'),
                containers: JSON.stringify(page.param.map(function (item) {
                    return {
                        containerID: item.ContainerID,
                        containerName: item.ContainerName,
                        productName: item.ProductName,
                        productID: item.ProductID,
                        qty: item.Qty,
                        taskNo: item.TaskNo
                    }
                }))
            };
            if (isNullOrWhiteSpaceStr(postData.operReason)) {
                displayMessage("请选择或填入释放原因", false);
                return;
            }
            if ($("#ddlIsMoveNon").combobox('getValue') == "是") {
                if (isNullOrWhiteSpaceStr($("#ddlWorkflow").textbox('getValue'))) {
                    displayMessage("未选择工艺", false);
                    return;
                }
                if (isNullOrWhiteSpaceStr($("#ddlWorkflowStep").textbox('getValue'))) {
                    displayMessage("未选择目标工序", false);
                    return;
                }

                var toProduct = $("#ddlProduct").combobox("getData").find(function (item) { return item.ProductID == $("#ddlProduct").combobox('getValue') });
                if (toProduct == null) {
                    displayMessage("未选择件号", false);
                    return;
                }
                var toStepItem = $("#ddlWorkflowStep").combobox("getData").find(function (item) { return item.WORKFLOWSTEPID == $("#ddlWorkflowStep").combobox('getValue') });

                postData.toProductId = toProduct.ProductID;
                postData.toProductBaseId = toProduct.ProductBaseID;
                postData.toProductRev = toProduct.ProductRev;
                postData.toProductDesc = toProduct.ProductDesc;
                postData.toWorkflowId = $("#ddlWorkflow").combobox('getValue');
                postData.toWorkflowName = $("#ddlWorkflow").combobox('getText').split(':')[0];
                postData.toWorkflowRev = $("#ddlWorkflow").combobox('getText').split(':')[1].split("(")[0];
                postData.toStep = toStepItem.WORKFLOWSTEPNAME;
                postData.toStepId = toStepItem.WORKFLOWSTEPID;
                postData.toSeq = toStepItem.SEQUENCE;
                postData.toStepCode = toStepItem.CONTROLCODE;

            }

            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        displayMessage("调度成功", true);

                        //若切换工艺判定新工艺是否需要重排
                        if (postData.curWorkflowId != postData.toWorkflowId && page.pageType != "2" && $("#ddlIsMoveNon").combobox('getValue') == "是") {
                            $.messager.confirm({
                                title: '提示',
                                msg: '切换到新工艺，是否重新自动排产？',
                                ok: "重排",
                                cancel: "取消",
                                fn: function (r) {
                                    if (r) {
                                        page.openChangeAps();
                                    } else {
                                        parent.$("#" + page.parentID).dialog('options').returnData = true;
                                        parent.$("#" + page.parentID).dialog('close');
                                    }
                                }
                            });
                        } else {
                            parent.$("#" + page.parentID).dialog('options').returnData = true;
                            parent.$("#" + page.parentID).dialog('close');
                        }

                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });

        },
        //非标移动
        moveNonStd: function () {
            if (isNullOrWhiteSpaceStr($("#ddlWorkflow").textbox('getValue'))) {
                displayMessage("未选择工艺", false);
                return;
            }
            if (isNullOrWhiteSpaceStr($("#ddlWorkflowStep").textbox('getValue'))) {
                displayMessage("未选择目标工序", false);
                return;
            }

            var toProduct = $("#ddlProduct").combobox("getData").find(function (item) { return item.ProductID == $("#ddlProduct").combobox('getValue') });
            if (toProduct == null) {
                displayMessage("未选择件号", false);
                return;
            }
            var toStepItem = $("#ddlWorkflowStep").combobox("getData").find(function (item) { return item.WORKFLOWSTEPID == $("#ddlWorkflowStep").combobox('getValue') });

            //请求后台，初始化数据
            var postData = {
                action: "moveNonStd",
                pageType: page.pageType,
                toProductId: toProduct.ProductID,
                toProductBaseId: toProduct.ProductBaseID,
                toProductRev: toProduct.ProductRev,
                toProductDesc: toProduct.ProductDesc,
                toWorkflowId: $("#ddlWorkflow").combobox('getValue'),
                toWorkflowName: $("#ddlWorkflow").combobox('getText').split(':')[0],
                toWorkflowRev: $("#ddlWorkflow").combobox('getText').split(':')[1].split("(")[0],
                toStep: toStepItem.WORKFLOWSTEPNAME,
                toStepId: toStepItem.WORKFLOWSTEPID,
                toSeq: toStepItem.SEQUENCE,
                toStepCode: toStepItem.CONTROLCODE,
                curWorkflowId: page.param[0].WorkFlowID,
                reason: $("#txtMoveReason").textbox('getValue'),
                containers: JSON.stringify(page.param.map(function (item) {
                    return {
                        containerID: item.ContainerID,
                        containerName: item.ContainerName,
                        productName: item.ProductName,
                        productID: item.ProductID,
                        qty: item.Qty,
                        taskNo: item.TaskNo
                    }
                }))
            };

            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        displayMessage("调度成功", true);
                        //若切换工艺判定新工艺是否需要重排
                        if (postData.curWorkflowId != postData.toWorkflowId && page.pageType != "2") {
                            $.messager.confirm({
                                title: '提示',
                                msg: '切换到新工艺，可选择操作？',
                                ok: "重排",
                                cancel: "继承",
                                fn: function (r) {
                                    if (r) {
                                        page.openChangeAps();
                                    } else {
                                        page.copyOldWorkflowApsData(postData);
                                    }
                                }
                            });
                        } else {
                            parent.$("#" + page.parentID).dialog('options').returnData = true;
                            parent.$("#" + page.parentID).dialog('close');
                        }

                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        //产品更改
        changeProduct: function () {
            var toProduct = $("#ddlProduct").combobox("getData").find(function (item) { return item.ProductID == $("#ddlProduct").combobox('getValue') });
            if (toProduct == null) {
                displayMessage("未选择件号", false);
                return;
            }

            //请求后台，初始化数据
            var postData = {
                action: "changeProduct",
                pageType: page.pageType,
                toProductId: toProduct.ProductID,
                toProductBaseId: toProduct.ProductBaseID,
                toProductRev: toProduct.ProductRev,
                toProductDesc: toProduct.ProductDesc,
                containers: JSON.stringify(page.param.map(function (item) {
                    return {
                        containerID: item.ContainerID,
                        productID: item.ProductID
                    }
                }))
            };

            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        displayMessage("调度成功", true);
                        parent.$("#" + page.parentID).dialog('options').returnData = true;
                        parent.$("#" + page.parentID).dialog('close');
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });

        },
        //非标调度后重排
        moveNonApsChange: function () {

            var toApsStepItem = $("#ddlApsToStep").combobox("getData").find(function (item) { return item.WORKFLOWSTEPID == $("#ddlApsToStep").combobox('getValue') });
            var preStepItem = $("#ddlPreStep").combobox("getData").find(function (item) { return item.WORKFLOWSTEPID == $("#ddlPreStep").combobox('getValue') });

            //请求后台，初始化数据
            var postData = {
                action: "moveNonApsChange",
                preWorkflowId: page.param[0].WorkFlowID,
                preStepId: preStepItem.WORKFLOWSTEPID,
                preStepSeq: preStepItem.SEQUENCE,
                preStepName: preStepItem.WORKFLOWSTEPNAME,
                toApsStepId: toApsStepItem.WORKFLOWSTEPID,
                toApsStepSeq: toApsStepItem.SEQUENCE,
                toApsStepName: toApsStepItem.WORKFLOWSTEPNAME,
                toApsWorkflowId: $("#ddlWorkflow").combobox('getValue'),
                apstype: "1",
                containers: JSON.stringify(page.param.map(function (item) {
                    return {
                        containerID: item.ContainerID,
                        containername: item.ContainerName,
                        workflowid: $("#ddlWorkflow").combobox('getValue'),
                        startTime: $("#txtApsStartDate").datetimebox('getValue'),
                        BeginSequence: parseInt(toApsStepItem.SEQUENCE) - 1,
                        CONTAINERTYPE: item.ContainerType,
                        TOGETHERFLAG: item.TogetherFlag,
                        DJDKSPECIAL: 2,
                        manualAdjust: 1//标记为手动调整后重排
                    }
                }))
            };

            if (isNullOrWhiteSpaceStr(postData.preStepId) || isNullOrWhiteSpaceStr(postData.toApsStepId) ||
                isNullOrWhiteSpaceStr($("#txtApsStartDate").datetimebox('getValue'))) {
                displayMessage("请输入必填项", false);
                return;
            }

            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        parent.displayMessage("重排成功", true);
                        parent.$("#" + page.parentID).dialog('options').returnData = true;
                        parent.$("#" + page.parentID).dialog('close');
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();

        },
        //复制批次的旧工艺的排产数据到新工艺排产数据中 add by zhangrj 20250723
        copyOldWorkflowApsData: function(postData) {
            postData.action = "CopyOldWorkflowApsData";//更改请求方法
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    displayMessage(result.Message, result.Result);
                    parent.$("#" + page.parentID).dialog('options').returnData = true;
                    parent.$("#" + page.parentID).dialog('close');
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        }
    }
    $(function () {
        page.init();
    });
</script>
